<template>
  <div class="bg">
    <el-row type="flex" justify="center">
      <el-col>
        <div class="loginContainer">
          <p><img src="~img/login/logo.png" height="80" width="80" alt="company_logo"></p>
          <h2>慧慧返利管理系统后台</h2>
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm">
            <el-form-item prop="username">
              <el-input v-model="ruleForm.username" placeholder="请输入账号" auto-complete="on" clearable></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input v-model="ruleForm.password" type="password" placeholder="请输入密码"
                        @keyup.enter.native="login"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="login">登录</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>

import { mapActions, mapGetters } from 'vuex'
import auth from '@/store/auth'

export default {
  data () {
    return {
      // 表单相关
      ruleForm: {
        ac: '',
        pwd: ''
      },
      rules: {
        username: [
          {required: true, message: '账号不能为空', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '密码不能为空', trigger: 'blur'},
          {min: 6, max: 16, message: '请输入6-16位密码', trigger: 'blur'}
        ]
      }
    }
  },
  computed: {
    ...mapGetters('center', ['LOGIN_DATA'])
  },
  methods: {
    ...mapActions('center', ['userLogin']),
    // 登录接口
    login () {
      let _this = this
      let loginParams = {
        username: _this.ruleForm.username,
        password: _this.ruleForm.password
      }
      _this.userLogin(loginParams)
      _this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          auth.setAuth(loginParams, '')
          console.log(loginParams)
        } else {
          _this.$message.error('请正确填写表单内容')
        }
      })
    }
  }
}
</script>

<style scoped lang="css">
  .bg {
    width: 100%;
    height: 100vh;
    min-height: 800px;
    text-align: center;
    background-size: cover;
    background-image: url('../../assets/images/login/wallpaper.png');
  }
  .el-col {
    width: 480px;
    background: rgba(255, 255, 255, 1);
    margin-top: 25vh;
  }
  .loginContainer {
    padding: 20px;
  }
  .el-form {
    padding: 20px;
    margin-top: 20px;

  }
  .el-button {
    width: 100%;
  }
  .el-form-item {
    margin-bottom: 20px;
  }
</style>
